clear
capture log close
set more off
set mem 500m



**** Table 6 Columns 1-4 with robust SEs ****

use data_pt_pop_1891, clear

*** Fix manchester and salford
replace loc="manchester" if loc=="salford"
count
collapse (sum) pop, by(loc year)
count

sort loc

merge loc using data_town_cotton_shr_1851

tab _merge
keep if _merge==3
drop _merge


** LHS var
gen log_pop=log(pop)

sort loc year
gen gr_pop=log_pop-log_pop[_n-1] if loc==loc[_n-1]


** RHS var
gen cotton10=0
replace cotton10=1 if shr_cot>.1

gen p1861=0
replace p1861=1 if year==1861
gen p1871=0
replace p1871=1 if year==1871
gen p1881=0
replace p1881=1 if year==1881
gen p1891=0
replace p1891=1 if year==1891

gen p1861cot10=p1861*cotton10
gen p1871cot10=p1871*cotton10
gen p1881cot10=p1881*cotton10
gen p1891cot10=p1891*cotton10


* Limit to textile cities only
gen shr_tex = shr_wool + shr_other_tex
gen tex=0
replace tex=1 if shr_tex>.1
replace tex=1 if shr_cot>.1
keep if tex==1


************ Regressions ***************

*** Panel regregssions
encode loc, gen(loc_code)
xtset loc_code year, yearly
drop if gr_pop==.

xi i.year

xtreg gr_pop p1861cot10  _I* if (year<1871), fe vce(robust)
est store FE0

xtreg gr_pop p1871cot10  _I* if (year>1851 & year<1881), fe vce(robust)
est store FE1

xtreg gr_pop p1871cot10  _I* if year<1881, fe vce(robust)
est store FE2

xtreg gr_pop p1871cot10 p1881cot10 p1891cot10 _I*, fe vce(robust)
est store FE3

outreg2 [FE0 FE1 FE2 FE3] using results_table_5_columns_1_to_4, tex replace see label  drop(_I*)



*********** Table 6 Columns 1-4 with spatial SEs ************
clear

use data_pt_pop_1891, clear

*** Fix manchester and salford
replace loc="manchester" if loc=="salford"
count
collapse (sum) pop, by(loc year)
count

sort loc

merge loc using data_town_cotton_shr_1851

tab _merge
keep if _merge==3
drop _merge


** LHS var
gen log_pop=log(pop)

sort loc year
gen gr_pop=log_pop-log_pop[_n-1] if loc==loc[_n-1]


** RHS var
gen cotton10=0
replace cotton10=1 if shr_cot>.1


gen p1861=0
replace p1861=1 if year==1861
gen p1871=0
replace p1871=1 if year==1871
gen p1881=0
replace p1881=1 if year==1881
gen p1891=0
replace p1891=1 if year==1891

gen p1861cot10=p1861*cotton10
gen p1871cot10=p1871*cotton10
gen p1881cot10=p1881*cotton10
gen p1891cot10=p1891*cotton10


* Limit to textile cities only
gen shr_tex = shr_wool + shr_other_tex
gen tex=0
replace tex=1 if shr_tex>.1
replace tex=1 if shr_cot>.1
keep if tex==1


***** Merge in lat and lon data
sort loc
merge loc using data_city_lat_lon_data
tab _merge
keep if _merge==3
drop _merge


***************
*** Panel regregssions
encode loc, gen(loc_code)
xtset loc_code year, yearly
drop if gr_pop==.
xi i.year i.loc
gen const=1


************ Regressions ***************

** Placebo 1841-1852 vs. 1851-1861
preserve
drop if year>1861
ols_spatial_HAC gr_pop p1861cot10 _Iyear_1861 _Iloc_2 _Iloc_3 _Iloc_4 _Iloc_5 _Iloc_6 _Iloc_7 _Iloc_8 _Iloc_9 _Iloc_10 _Iloc_11 _Iloc_12 _Iloc_13 _Iloc_14 _Iloc_15 _Iloc_16 _Iloc_17 _Iloc_18  const, lat(lat) lon(lon) timevar(year) panelvar(loc_code) distcutoff(100) lagcutoff(0) star
est store FE0
outreg2 [FE0] using results_table_5_column_1_spatial_SEs, tex replace see label  drop(_I*)
restore


** Baseline: 1851-1861 vs 1861-1871
preserve
keep if year>1851 & year<1881
ols_spatial_HAC gr_pop p1871cot10 _Iyear_1871 _Iloc_2 _Iloc_3 _Iloc_4 _Iloc_5 _Iloc_6 _Iloc_7 _Iloc_8 _Iloc_9 _Iloc_10 _Iloc_11 _Iloc_12 _Iloc_13 _Iloc_14 _Iloc_15 _Iloc_16 _Iloc_17 _Iloc_18 const, lat(lat) lon(lon) timevar(year) panelvar(loc_code) distcutoff(100) lagcutoff(0) star
est store FE0
outreg2 [FE0] using results_table_5_column_2_spatial_SEs, tex replace see label  drop(_I*)
restore

** Longer pre-period 1841-1861 vs. 1861-1871
preserve
keep if year<1881
ols_spatial_HAC gr_pop p1871cot10 _Iyear_1861 _Iyear_1871 _Iloc_2 _Iloc_3 _Iloc_4 _Iloc_5 _Iloc_6 _Iloc_7 _Iloc_8 _Iloc_9 _Iloc_10 _Iloc_11 _Iloc_12 _Iloc_13 _Iloc_14 _Iloc_15 _Iloc_16 _Iloc_17 _Iloc_18 const, lat(lat) lon(lon) timevar(year) panelvar(loc_code) distcutoff(100) lagcutoff(0) star
est store FE0
outreg2 [FE0] using results_table_5_column_3_spatial_SEs, tex replace see label  drop(_I*)
restore

** Long pre and post
preserve
ols_spatial_HAC gr_pop p1871cot10 p1881cot10 p1891cot10 _Iyear_1861 _Iyear_1871 _Iyear_1881 _Iyear_1891 _Iloc_2 _Iloc_3 _Iloc_4 _Iloc_5 _Iloc_6 _Iloc_7 _Iloc_8 _Iloc_9 _Iloc_10 _Iloc_11 _Iloc_12 _Iloc_13 _Iloc_14 _Iloc_15 _Iloc_16 _Iloc_17 _Iloc_18 const, lat(lat) lon(lon) timevar(year) panelvar(loc_code) distcutoff(100) lagcutoff(0) star
est store FE0
outreg2 [FE0] using results_table_5_column_4_spatial_SEs, tex replace see label  drop(_I*)
restore



***************** Table 6 Column 5 with robust SEs ************
clear

use data_pt_pop_1901, clear

*** Fix manchester and salford
replace loc="manchester" if loc=="salford"
count
collapse (sum) pop, by(loc year)
count

sort loc

merge loc using data_town_cotton_shr_1851
tab _merge
keep if _merge==3
drop _merge


** LHS var
gen log_pop=log(pop)

sort loc year
gen gr_pop=log_pop-log_pop[_n-1] if loc==loc[_n-1]


** RHS var
gen cotton10=0
replace cotton10=1 if shr_cot>.1

gen p1871=0
replace p1871=1 if year==1871
gen p1881=0
replace p1881=1 if year==1881
gen p1891=0
replace p1891=1 if year==1891
gen p1901=0
replace p1901=1 if year==1901

gen p1871cot10=p1871*cotton10
gen p1881cot10=p1881*cotton10
gen p1891cot10=p1891*cotton10
gen p1901cot10=p1901*cotton10


* Limit to textile cities only
gen shr_tex = shr_wool + shr_other_tex
gen tex=0
replace tex=1 if shr_tex>.1
replace tex=1 if shr_cot>.1
keep if tex==1


************ Regressions ***************

*** Panel regregssions
encode loc, gen(loc_code)
xtset loc_code year, yearly
drop if gr_pop==.

xi i.year


xtreg gr_pop p1871cot10 p1881cot10 p1891cot10 p1901cot10 _I*, fe vce(robust)
est store REG

outreg2 [REG] using results_table_5_column_5, tex replace see label  drop(_I*)



******************* Table 6 Column 5 with spatial SEs ****************
clear

use data_pt_pop_1901, clear

*** Fix manchester and salford
replace loc="manchester" if loc=="salford"
count
collapse (sum) pop, by(loc year)
count

sort loc

merge loc using data_town_cotton_shr_1851

tab _merge
keep if _merge==3
drop _merge


** LHS var
gen log_pop=log(pop)

sort loc year
gen gr_pop=log_pop-log_pop[_n-1] if loc==loc[_n-1]


** RHS var
gen cotton10=0
replace cotton10=1 if shr_cot>.1


gen p1861=0
replace p1861=1 if year==1861
gen p1871=0
replace p1871=1 if year==1871
gen p1881=0
replace p1881=1 if year==1881
gen p1891=0
replace p1891=1 if year==1891
gen p1901=0
replace p1901=1 if year==1901

gen p1861cot10=p1861*cotton10
gen p1871cot10=p1871*cotton10
gen p1881cot10=p1881*cotton10
gen p1891cot10=p1891*cotton10
gen p1901cot10=p1901*cotton10


* Limit to textile cities only
gen shr_tex = shr_wool + shr_other_tex
gen tex=0
replace tex=1 if shr_tex>.1
replace tex=1 if shr_cot>.1
keep if tex==1


***** Merge in lat and lon data
sort loc
merge loc using data_city_lat_lon_data
tab _merge
keep if _merge==3
drop _merge



***************
*** Panel regregssions
encode loc, gen(loc_code)
xtset loc_code year, yearly
drop if gr_pop==.
xi i.year i.loc
gen const=1


************ Regressions ***************

** Long pre and post with placebo
ols_spatial_HAC gr_pop p1871cot10 p1881cot10 p1891cot10 p1901cot10  _Iyear_1871 _Iyear_1881 _Iyear_1891 _Iyear_1901 _Iloc_2 _Iloc_3 _Iloc_4 _Iloc_5 _Iloc_6 _Iloc_7 _Iloc_8 _Iloc_9 _Iloc_10 _Iloc_11 _Iloc_12 _Iloc_13 _Iloc_14 _Iloc_15 _Iloc_16 _Iloc_17 _Iloc_18 const, lat(lat) lon(lon) timevar(year) panelvar(loc_code) distcutoff(100) lagcutoff(0) star
est store FE0

outreg2 [FE0] using results_table_5_column_5_spatial, tex replace see label  drop(_I*)



*****



